<?php

namespace Biz\service\bizAd;

use Biz\cache\bizAd\CtrWhite;
use Biz\model\bizAd\AdPlan as mAdPlan;
use Biz\model\bizAd\AdPlanDataFlow as mAdPlanDataFlow;
use Biz\model\bizAd\AdPrice as mAdPrice;
use Biz\model\bizAd\AdWalletLog as mAdWalletLog;
use Biz\model\brand\Brand as mBrand;
use Biz\model\brand\Content as mBrandContent;
use Biz\model\brandData\ContentCtr;
use Biz\service\wiki\WikiContent;
use Doraemon\model\AdmUserType;
use Doraemon\model\Article as mArticle;
use Doraemon\model\Blank as mBlank;
use Doraemon\model\Flow\FlowPackage as mFlowPackage;
use Doraemon\model\Photos as mPhotos;
use Doraemon\model\Position\PositionRules;
use Doraemon\service\es\EsMainContent;
use Doraemon\service\Photos;
use Doraemon\service\position\AdmOperationModule;
use Doraemon\service\User;
use Doraemon\service\Videos\Videos;
use Doraemon\tools\BlockType;
use Doraemon\tools\HhzEnv;
use Doraemon\tools\IdParse;
use Doraemon\tools\ImgUrl;
use Doraemon\tools\Log;
use Doraemon\tools\ParticipleKeyword;

class AdPlan
{

    public static function getPlanList($uid, $page, $pageSize = 20)
    {
        $page = $page ?? 1;
        $where = [
            'uid' => $uid,
            'plan_status[!]' => mAdPlan::PLAN_STATUS_DELETE,
            'LIMIT' => [($page - 1) * $pageSize, $pageSize],
            'ORDER' => ['id' => 'DESC']
        ];
        $list = mAdPlan::getPlanList($where);
        $total = mAdPlan::dataCount(['uid' => $uid, 'plan_status[!]' => mAdPlan::PLAN_STATUS_DELETE]);
        $isOver = (($page * $pageSize) >= $total) ? 1 : 0;
        return [$list, $total, $isOver];
    }

    public static function getPlanInfo($planId)
    {
        $info = mAdPlan::getPlanInfo($planId);
        if ($info) {
            $brandId = mBrand::getBrandIdByUid($info['uid']);
            $brandContentInfo = $brandId ? mBrandContent::getAllByBidAndOid($info['obj_id'], $brandId) : [];
            $idExtendArr = [];
            if ($brandContentInfo) {
                $brandContentInfo = array_shift($brandContentInfo);
                $idExtendArr[$info['obj_id']] = [
                    'id' => $info['obj_id'],
                    'time' => strtotime($brandContentInfo['claim_time'])
                ];
            }
            $content = self::formatContent([$info['obj_id']], $idExtendArr, false);
            $info['content'] = $content ? array_shift($content) : [];
        }
        return $info;
    }

    public static function getUserPackage()
    {
        $res = mAdPrice::getAllPrice();
        $userPackage = [];
        foreach ($res as $row) {
            if (!isset($userPackage[$row['package']])) {
                $userPackage[$row['package']] = [
                    'package' => $row['package'],
                    'package_name' => $row['package_name'],
                    'package_desc' => $row['package_desc'],
                    'plan_price' => []
                ];
            }
            $discount = ($row['price'] < $row['original_price']) ? round($row['price'] / $row['original_price'] * 10, 1) : 0;
            $discount = (string)$discount;
            $userPackage[$row['package']]['plan_price'][] = [
                'original_price' => $row['original_price'],
                'price' => $row['price'],
                'discount' => $discount,
                'count' => $row['count'],
                'total_price' => $row['total_price'],
            ];
        }
        return $userPackage;
    }

    /**
     * 创建投放计划
     * @param $data
     * @param $isStart 是否开始投放
     * @return false|int
     * @throws \Exception
     */
    public static function createPlan($data, $isStart = false)
    {
        $planId = mAdPlan::addPlan($data);
        if ($isStart) {
            $res = self::startPlan($planId);
            if (!$res) {
                throw new \Exception('开始投放计划失败');
            }
        }
        return $planId;
    }

    /**
     * 开始投放
     * @param $planId
     * @return bool
     * @throws \Exception
     */
    public static function startPlan($planId)
    {
        $planInfo = mAdPlan::getPlanInfo($planId);
        //扣费
        $hasLog = mAdWalletLog::dataHas(['op_type' => mAdWalletLog::OP_TYPE_CONSUME, 'op_rel_id' => $planId, 'uid' => $planInfo['uid']]);
        if ($hasLog) {
            Log::error('已经存在扣费账单', ['plan_id' => $planId, 'uid' => $planInfo['uid']]);
            return false;
        }
        $deductRes = AdWallet::deduct($planInfo['uid'], $planInfo['utype'], $planInfo['buy_amount'], $planInfo['id'], $planInfo['plan_name']);
        Log::info('开始投放-扣费', ['plan_id' => $planId, 'uid' => $planInfo['uid'], 'deduct_res' => $deductRes]);
        if (!$deductRes) {
            Log::error('扣费失败', ['plan_id' => $planId, 'uid' => $planInfo['uid'], 'deduct_res' => $deductRes]);
            return false;
        }

        list($startTime, $endTime, $settleTime) = AdPlan::getStartEndTime(
            date('Y-m-d', $planInfo['start_time']),
            date('Y-m-d', $planInfo['end_time'])
        );
        mAdPlan::updatePlan($planId, [
            'start_time' => $startTime,
            'end_time' => $endTime,
            'plan_status' => mAdPlan::PLAN_STATUS_OPEN,
            'settle_time' => $settleTime
        ]);
        $planInfo['start_time'] = $startTime;
        $planInfo['end_time'] = $endTime;
        //创建加油包
        self::createFlow($planInfo);
        return true;
    }

    /**
     * 创建加油包
     * @param $planInfo
     * @return false|int
     * @throws \Exception
     */
    public static function createFlow($planInfo, $type = mAdPlanDataFlow::TYPE_CREATE)
    {
        $result = false;
        $package = $planInfo['user_package'];
        $title = self::createFlowPackageTitle($planInfo);
        $flowData = [
            'title' => $title,
            'obj_type' => mFlowPackage::OBJ_TYPE_ID,//IdParse::getType($planInfo['obj_id']),
            'obj_value' => $planInfo['obj_id'],
            'flow_type' => mFlowPackage::FLOW_TYPE_PACKAGE,
            'target_exposure' => bcmul($planInfo['target_count'], $planInfo['flow_rate']),
            'start_time' => date('Y-m-d H:i:s', $planInfo['start_time']),
            'end_time' => date('Y-m-d H:i:s', $planInfo['end_time']),
            'admin_id' => 0,
            'pos' => mFlowPackage::POS_RECOMMEND_FEED,//推荐线
        ];
        $flowPackageId = mFlowPackage::add($flowData);
        if ($flowPackageId) {
            if ($package && $type == mAdPlanDataFlow::TYPE_CREATE) {//追加流量包，用户分群为全部用户
                $userProfile['is_all'] = 4;
                $userProfile['custom'] = $package;
                AdmOperationModule::addUserProfile($flowPackageId, $userProfile, PositionRules::MODULE_TYPE_FLOW_PACKAGE);
            }
            $planFlowData = [
                'uid' => $planInfo['uid'],
                'plan_id' => $planInfo['id'],
                'type' => $type,
                'flow_package_id' => $flowPackageId,
                'plan_flow_no' => $title,
            ];
            $result = mAdPlanDataFlow::addData($planFlowData);
            Log::info('投放计划，已创建加油包', ['flow_package_id' => $flowPackageId, 'plan_id' => $planInfo['id']]);
        }
        return $result;
    }

    /**
     * 更新流量包
     * @param $flowInfo
     */
    public static function changeExposeFromFlow($flowInfo, $num = 1)
    {
        $now = time();
        $dataInfo = mAdPlanDataFlow::getInfoByWhere(['flow_package_id' => $flowInfo['id']]);
        $planId = $dataInfo ? $dataInfo['plan_id'] : 0;
        if ($planId) {
            //更新曝光量
            $info = mAdPlan::getPlanInfo($planId);
            $flowRate = $info['flow_rate'];
            $count = $info['expose_count'] + $num;

            $flowPackageIds = mAdPlanDataFlow::getFlowPackageIdsByWhere(['plan_id' => $planId]);
            //查询加油包的曝光量
            $flowArr = mFlowPackage::select(['id', 'real_exposure'], ['id' => $flowPackageIds, 'package_status[!]' => mFlowPackage::STATUS_DELETE]);
            $flowExposure = 0;
            foreach ($flowArr as $row) {
                $flowExposure += $row['real_exposure'];
            }
            //对比加油包的曝光量，是否一致，如果不想等，则使用加油包的曝光量
            if ($count != $flowExposure && $flowExposure) {
                $count = $flowExposure;
            }

            $exposeCount = floor(bcdiv($count, $flowRate));//真实曝光除以曝光比例

            $res = mAdPlan::updatePlan($planId, ['real_expose_count' => $count, 'expose_count' => $exposeCount]);
            Log::info('更新计划曝光量', [
                'flow_package_id' => $flowInfo['id'],
                'plan_id' => $planId,
                'target_count' => $info['target_count'],
                'old_expose_count' => $info['expose_count'],
                'change_expose_count' => $exposeCount,
                'old_real_expose_count' => $info['real_expose_count'],
                'change_real_expose_count' => $count,
                'sql' => mAdPlan::log()
            ]);
            if ($res) {
                //完成任务，终止计划下所有流量包
                if ($count >= $info['real_target_count']) {
                    if ($flowPackageIds) {
                        Log::info('更新计划曝光量,计划已达量,终止加油包#加油包id:', $flowPackageIds);
                        mFlowPackage::update(['package_status' => mFlowPackage::STATUS_FINISH], ['id' => $flowPackageIds]);
                    }
                    Log::info('更新计划曝光量,计划已达量,更新结算时间#计划id:' . $planId);
                    $data = ['settle_time' => $now + mAdPlan::SETTLE_DELAY];
                    if ($exposeCount < $info['target_count']) {
                        $data['expose_count'] = $info['target_count'];
                    }
                    mAdPlan::updatePlan($planId, $data);//更新结算时间
                }
            }
        }
    }

    /**
     * 结算投放计划
     * @param $planInfo
     * @return false|void
     */
    public static function settlePlan($planInfo)
    {
        $hasSettled = mAdWalletLog::dataHas(['op_type' => mAdWalletLog::OP_TYPE_RELEASE_LOCK_AMOUNT, 'op_rel_id' => $planInfo['id'], 'uid' => $planInfo['uid']]);
        if ($hasSettled || $planInfo['settle_status'] == mAdPlan::SETTLE_STATUS_FINISH) {
            Log::error('已经结算的投放计划', ['plan_info' => $planInfo]);
            return false;
        }

        $diffCount = $planInfo['target_count'] - $planInfo['expose_count'];
        $diffCount = $diffCount > 0 ? $diffCount : 0;

        if ($diffCount) {
            //实际花费金额
            $amount = round(bcmul(bcdiv($planInfo['expose_count'], 1000, 3), $planInfo['price'], 3), 2);
            //返还金额
            $refundAmount = bcsub($planInfo['buy_amount'], $amount, 2);
            $refundAmount = ($refundAmount > 0) ? $refundAmount : 0;
            if (bccomp(bcadd($refundAmount, $amount, 2), $planInfo['buy_amount'], 2) != 0) {
                Log::error('计算返还金额错误', [
                    'plan_id' => $planInfo['id'],
                    'expose_count' => $planInfo['expose_count'],
                    'price' => $planInfo['price'],
                    'buy_amount' => $planInfo['buy_amount'],
                    'refundAmount' => $refundAmount, 'amount' => $amount,
                    'amount' => $amount
                ]);
                return false;
            }
        } else {
            $amount = $planInfo['buy_amount'];
            $refundAmount = 0;
        }
        $settleRes = AdWallet::unlockAmount($planInfo['uid'], $planInfo['utype'], $refundAmount, $planInfo['buy_amount'], $planInfo['id'], $planInfo['plan_name']);
        Log::info('投放计划结算', ['plan_id' => $planInfo['id'], 'uid' => $planInfo['uid'], 'settle_res' => $settleRes]);
        if (!$settleRes) {
            Log::error('投放计划结算失败', ['plan_id' => $planInfo['id'], 'uid' => $planInfo['uid'], 'settle_res' => $settleRes]);
            return false;
        }
        mAdPlan::updatePlan($planInfo['id'], [
            'refund_amount' => $refundAmount,
            'amount' => $amount,
            'settle_status' => mAdPlan::SETTLE_STATUS_FINISH
        ]);
        return true;
    }

    /**
     * @param $planInfo 计划info
     * @param string $place 渠道/位置 A:推荐线 B:更多推荐线
     * @return string
     */
    private static function createFlowPackageTitle($planInfo, $place = 'A')
    {
        $title = '';
        if ($planInfo) {
            $planId = $planInfo['id'];
            $dataList = mAdPlanDataFlow::getPlanDataList($planId);
            $count = $dataList ? count($dataList) : 0;
            $num = $count + 1;
            $planNo = self::getPlanNo($planInfo, $place);
            $title = $planNo ? ($planNo . $num) : '';
        }
        return $title;
    }

    /**
     * 获取计划编码
     * @param $planInfo 计划info
     * @param string $place 渠道/位置 A:推荐线 B:更多推荐线
     * @return void
     */
    public static function getPlanNo($planInfo, $place = 'A')
    {
        $planNo = '';
        if ($planInfo) {
            $planId = $planInfo['id'];
            $userType = $planInfo['utype'];
            $adType = $planInfo['ad_type'];
            $planNo = mAdPlan::AD_TYPE[$adType] . $planId . 'UT' . $userType . $place;
        }
        return $planNo;
    }

    public static function getPlanIdByPlanFlowNo($planFlowNo)
    {
        $str = str_replace(array_values(mAdPlan::AD_TYPE), '', $planFlowNo);
        $planId = substr($str, 0, strpos($str, 'UT'));
        return is_numeric($planId) ? $planId : false;
    }

    /**
     * @param string $startDay 开始日期（天 Y-m-d）
     * @param string $endDay 结束日期（天 Y-m-d）
     * @return array
     */
    public static function getStartEndTime($startDay, $endDay, $isStart = true)
    {
        if ($isStart) {
            $today = date('Y-m-d');
            $todayTime = strtotime($today);
            if (strtotime($startDay) <= $todayTime) {
                $startTime = time();
            } else {
                $startTime = strtotime($startDay);
            }
            $endTime = $startTime + (strtotime($endDay) - strtotime($startDay));
        } else {
            $startTime = strtotime($startDay);
            $endTime = strtotime($endDay);
        }
        $settleTime = $endTime + mAdPlan::SETTLE_DELAY;

        return [$startTime, $endTime, $settleTime];
    }

    public static function getContent($type, $uid, $page = 1, $keyWord = '', $startDate = '', $endDate = '', $pageSize = 20)
    {
        //7-365天的内容
        $limitStartDay = date('Y-m-d', strtotime('-365 days'));
        $limitEndDay = date('Y-m-d', strtotime('-6 days'));

        if ($startDate < $limitStartDay || empty($startDate)) {
            $startDate = $limitStartDay;
        }
        if ($endDate > $limitEndDay || empty($endDate)) {
            $endDate = $limitEndDay;
        } else if ($endDate) {
            $endDate = date('Y-m-d H:i:s', strtotime(date('Y-m-d', strtotime($endDate))) + 86399);
        }
        $ids = [];
        $idExtendArr = [];
        $total = 0;
        $isOver = 1;
        switch ($type) {
            case 1://品牌自己发布
                list($ids, $total, $isOver) = self::getUserContent($uid, $page, $keyWord, $startDate, $endDate, $pageSize);
                break;
            case 2://品牌收录
                list($res, $total, $isOver) = self::getClaimContent($uid, $page, $keyWord, $startDate, $endDate, $pageSize);
                $ids = array_column($res, 'id');
                $idExtendArr = $res;
                break;
        }
        if (HhzEnv::isShopTest()) {
            //$ids = ['00007bp050013n8y', '0004brw01000x2bv', '000ncqw000015zgh'];//todo debug
        }
        $list = self::formatContent($ids, $idExtendArr);
        return [$list, $total, $isOver];
    }

    private static function formatContent($ids, $idExtendArr = [], $isFilter = true)
    {
        Log::info('format-content-ids', $ids);
        $contentInfos = [];
        $noteIds = [];
        $articleIds = [];
        $blankIds = [];
        $uids = [];
        $contentCtrList = ContentCtr::getContentList($ids);
        $contentCtrList = array_column($contentCtrList, null, 'obj_id');
        foreach ($ids as $id) {
            $type = IdParse::getType($id);
            $uids[] = IdParse::getUid($id);
            switch ($type) {
                case BlockType::TYPE_PHOTO:
                case BlockType::TYPE_ANSWER:
                    $noteIds[] = $id;
                    break;
                case BlockType::TYPE_ARTICLE:
                    $articleIds[] = $id;
                    break;
                case BlockType::TYPE_BLANK:
                    $blankIds[] = $id;
                    break;
            }
        }
        $uids = array_filter(array_unique($uids));
        $userList = User::getBatchBasicUserInfo($uids);
        $userList = array_column($userList, null, 'uid');
        $beleveUids = AdmUserType::isBlevelMulti($uids);

        $noteInfos = $noteIds ? mPhotos::getPhotos($noteIds) : [];

        $video_ids = array_filter(array_unique(array_column($noteInfos, 'video_id')));

        $videos = Videos::getCanUseVideoInfosByIds($video_ids);

        $articleInfos = $articleIds ? mArticle::getArticles($articleIds) : [];
        $articleInfos = $articleInfos ? array_column($articleInfos, null, 'aid') : [];
        $blankInfos = $blankIds ? mBlank::getBatchBlankByIds($blankIds) : [];
        $blankInfos = $blankInfos ? array_column($blankInfos, null, 'bid') : [];
        $adminScore = 70;
        $minCtr = 0.046;
        $ctrWhiteList = CtrWhite::getWhite();
        foreach ($ids as $id) {
            $ctr = $contentCtrList[$id]['ctr'] ?? 0;
            if (in_array($id, $ctrWhiteList)) {
                $ctr = 1;//ctr白名单
            }
            $type = IdParse::getType($id);
            switch ($type) {
                case BlockType::TYPE_PHOTO:
                case BlockType::TYPE_ANSWER:
                    if (isset($noteInfos[$id])) {
                        $photoInfo = $noteInfos[$id];
                        $uid = $photoInfo['uid'];
                        if ($isFilter) {
                            $isBeleve = in_array($uid, $beleveUids);
                            if ($isBeleve || $photoInfo['admin_score'] < $adminScore || $ctr < $minCtr) {
                                Log::info('已被过滤#photo_id:' . $id . '#admin_score:' . $photoInfo['admin_score'] . '#ctr:' . $ctr . '#uid:' . $uid . '#是否B级：' . ($isBeleve ? '是' : '否'));
                                break;
                            }
                        }
                        $time = isset($idExtendArr[$id]['time']) ? date('Y-m-d', $idExtendArr[$id]['time']) : date('Y-m-d', $photoInfo['addtime']);

                        if (Photos::SHOW_TYPE_VIDEO == $photoInfo['show_type']) {
                            $picUrl = $videos[$photoInfo['video_id']] ? $videos[$photoInfo['video_id']]['thumb_pic_url'] : '';
                        } else {
                            $picUrl = ImgUrl::getUrl(ImgUrl::APPTYPE_APP, $photoInfo['pic_id'], ImgUrl::IMAGE_SIZE_1280);
                        }

                        $contentInfos[] = [
                            'id' => $id,
                            'type' => BlockType::TYPE_PHOTO,
                            'title' => $photoInfo['title'],
                            'remark' => $photoInfo['remark'],
                            'pic_url' => $picUrl,
                            'time' => $time,
                            'score' => $photoInfo['admin_score'],
                            'ctr' => $ctr,
                            'uid' => $uid,
                            'nick' => $userList[$uid]['nick'] ?? '',
                        ];
                    }
                    break;
                case BlockType::TYPE_ARTICLE:
                    if (isset($articleInfos[$id])) {
                        $articleInfo = $articleInfos[$id];
                        $uid = $articleInfo['uid'];
                        if ($isFilter) {
                            $isBeleve = in_array($uid, $beleveUids);
                            if ($isBeleve || $articleInfo['admin_score'] < $adminScore || $ctr < $minCtr) {
                                Log::info('已被过滤#article_id:' . $id . '#admin_score:' . $articleInfo['admin_score'] . '#ctr:' . $ctr . '#uid:' . $uid . '#是否B级：' . ($isBeleve ? '是' : '否'));
                                break;
                            }
                        }
                        $contentInfos[] = [
                            'id' => $id,
                            'type' => BlockType::TYPE_ARTICLE,
                            'title' => $articleInfo['title'],
                            'remark' => $articleInfo['remark'],
                            'pic_url' => ImgUrl::getUrl(ImgUrl::APPTYPE_APP, $articleInfo['cover_pic_id'], ImgUrl::IMAGE_SIZE_ORI_NPHONE),
                            'time' => date('Y-m-d', $articleInfo['addtime']),
                            'score' => $articleInfo['admin_score'],
                            'ctr' => $ctr,
                            'uid' => $uid,
                            'nick' => $userList[$uid]['nick'] ?? '',
                        ];
                    }
                    break;
                case BlockType::TYPE_BLANK:
                    if (isset($blankInfos[$id])) {
                        $blankInfo = $blankInfos[$id];
                        $uid = $blankInfo['uid'];
                        if ($isFilter) {
                            $isBeleve = in_array($uid, $beleveUids);
                            if ($isBeleve || $blankInfo['admin_score'] < $adminScore || $ctr < $minCtr) {
                                Log::info('已被过滤#blank_id:' . $id . '#admin_score:' . $blankInfo['admin_score'] . '#ctr:' . $ctr . '#uid:' . $uid . '#是否B级：' . ($isBeleve ? '是' : '否'));
                                break;
                            }
                        }
                        $time = isset($idExtendArr[$id]['time']) ? date('Y-m-d', $idExtendArr[$id]['time']) : date('Y-m-d', $blankInfo['addtime']);
                        $contentInfos[] = [
                            'id' => $id,
                            'type' => BlockType::TYPE_BLANK,
                            'title' => $blankInfo['title'],
                            'remark' => $blankInfo['remark'],
                            'pic_url' => ImgUrl::getUrl(ImgUrl::APPTYPE_APP, $blankInfo['cover_pic_id'], ImgUrl::IMAGE_SIZE_ORI_NPHONE),
                            'time' => $time,
                            'score' => $blankInfo['admin_score'],
                            'ctr' => $ctr,
                            'uid' => $uid,
                            'nick' => $userList[$uid]['nick'] ?? '',
                        ];
                    }
                    break;
            }
        }
        return $contentInfos;
    }

    private static function getUserContent($uid, $page = 1, $keyWord = '', $startDate = '', $endDate = '', $pageSize = 20)
    {
        $ids = [];
        $total = 0;
        $isOver = 1;
        $params = [
            'search_type' => 'time',
            'uid' => $uid,
            'type' => [
                BlockType::TYPE_PHOTO,
                BlockType::TYPE_ARTICLE,
                BlockType::TYPE_BLANK,
            ],
            "fl" => "id",
        ];

        if ($startDate && $endDate) {
            $params['min_addtime'] = strtotime($startDate);
            $params['max_addtime'] = strtotime($endDate);
        }

        $keyWord = \Doraemon\service\search\Schedule::transformT2S($keyWord);
        $handleKeyword = ParticipleKeyword::getParticipleKeyword($keyWord);
        Log::info('es-main-content-params#keyword:' . $handleKeyword, $params);
        $rs = EsMainContent::searchInHomepage($handleKeyword, $page, $pageSize, $params);
        if (is_array($rs) && isset($rs['rows']) & $rs['rows']) {
            $ids = array_column($rs['rows'], 'id');
        }
        Log::info('es-main-content-ids', $ids);
        return [$ids, $total, $isOver];
    }

    private static function getClaimContent($uid, $page = 1, $keyWord = '', $startDate = '', $endDate = '', $pageSize = 20)
    {
        $brandInfo = mBrand::getBrandInfoByUid($uid);
        $brandId = $brandInfo['id'];
        $condition = [];
        if ($keyWord) {
            $condition['word'] = $keyWord;
        }
        $condition['fl'] = 'obj_id,claim_time';
        $condition['publisher'] = 1;
        if ($startDate && $endDate) {
            $condition['claimtime_s'] = $startDate;
            $condition['claimtime_e'] = $endDate;
        }
        Log::info('es-claim-content-params', $condition);
        $esData = WikiContent::getEsContent($brandId, $page, 1, [], $condition, $pageSize);
        $esRes = $esData['list'];
        $res = [];
        foreach ($esRes as $row) {
            $res[$row['obj_id']] = [
                'id' => $row['obj_id'],
                'time' => $row['claim_time']
            ];


        }
        Log::info('es-claim-content-ids', $res);
        $total = $esData['total'];
        $isOver = $esData['is_over'];
        return [$res, $total, $isOver];
    }
}